package com.youan.log.modules.audit.dataanalysis;

import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

public class SaveOrUpdateBatchUtil {
    public static <T extends IService, Y> void batch(T service, List<Y> list) {
        // 批量插入
        int listSize = list.size();
        int toIndex = 5000;
        for(int i = 0; i<list.size(); i += 5000){
            if(i + 5000 > listSize){//作用为toIndex最后没有800条数据则剩余几条newList中就装几条
                toIndex = listSize - i;
            }
            List<Y> newList = list.subList(i,i+toIndex);
            service.saveOrUpdateBatch(newList);
        }
    }
}
